using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace XnaDevRu.Bullet
{
	public class FilteredCallback : InternalTriangleIndexCallback
	{
		private ITriangleCallback _callback;
		private Vector3 _aabbMin;
		private Vector3 _aabbMax;

		public FilteredCallback(ITriangleCallback callback, Vector3 aabbMin, Vector3 aabbMax)
		{
			_callback = callback;
			_aabbMin = aabbMin;
			_aabbMax = aabbMax;
		}

		public ITriangleCallback TriangleCallback { get { return _callback; } set { _callback = value; } }
		public Vector3 AabbMin { get { return _aabbMin; } set { _aabbMin = value; } }
		public Vector3 AabbMax { get { return _aabbMax; } set { _aabbMax = value; } }

		public override void InternalProcessTriangleIndex(Vector3[] triangle, int partId, int triangleIndex)
		{
			if (MathHelper.TestTriangleAgainstAabb2(triangle, _aabbMin, _aabbMax))
			{
				//check aabb in triangle-space, before doing this
				_callback.ProcessTriangle(triangle, partId, triangleIndex);
			}
		}
	}
}
